package com.wanxi.education.scheduler;

import com.wanxi.education.model.vo.order.OrderDelayVo;
import com.wanxi.education.service.OrderFrontService;
import com.wanxi.education.util.ApplicationContextUtil;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.concurrent.DelayQueue;

/**
 * @Author: 寇文宝
 * @Description: 订单支付定时器
 * @Date: Created in 2021/9/6
 * @Version: 1.0
 */

public class OrderCheckScheduler implements Runnable {
    //延时队列
    private DelayQueue queue;

    // 注入orderService
    OrderFrontService orderFrontService = (OrderFrontService) ApplicationContextUtil.getBean("orderFrontService");
//    @Autowired
//    private OrderFrontService orderFrontService;

    public OrderCheckScheduler(DelayQueue queue) {
        this.queue = queue;
    }

    @Override
    public void run() {
        while (true) {
            try {
                OrderDelayVo take = (OrderDelayVo) queue.take();
                orderFrontService.autoCancelOrder(take.getId());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
